//
//  LSPersonalInfoTextCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/20.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSPersonalInfoTextCell.h"

@interface LSPersonalInfoTextCell ()
@property (nonatomic, strong) UILabel *mainTextLabel;
@property (nonatomic, strong) UILabel *subtitleTextLabel;
@property (nonatomic, strong) UIImageView *rightArrowImageView;
@end

@implementation LSPersonalInfoTextCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
        lineView.backgroundColor = hexColor(EEEEEE);
        [self.contentView addSubview:lineView];
        [self.contentView addSubview:self.mainTextLabel];
        [self.contentView addSubview:self.subtitleTextLabel];
        [self.contentView addSubview:self.rightArrowImageView];
    }
    return self;
}

- (void)setMainText:(NSString *)mainText {
    _mainText = mainText;
    self.mainTextLabel.text = mainText;
}

- (void)setSubtitleText:(NSString *)subtitleText {
    _subtitleText = subtitleText;
    self.subtitleTextLabel.text = subtitleText;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    WS
    if (highlighted) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    WS
    if (selected) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    WS
    [self.mainTextLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
        make.centerY.equalTo(weakSelf.contentView.mas_centerY).with.offset(5);
    }];
    [self.subtitleTextLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-30);
        make.centerY.equalTo(weakSelf.contentView.mas_centerY).with.offset(5);
    }];
}

- (UILabel *)mainTextLabel {
    if (!_mainTextLabel) {
        _mainTextLabel = [[UILabel alloc] init];
        _mainTextLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:11];
        _mainTextLabel.textColor = hexColor(333333);
    }
    return _mainTextLabel;
}

- (UILabel *)subtitleTextLabel {
    if (!_subtitleTextLabel) {
        _subtitleTextLabel = [[UILabel alloc] init];
        _subtitleTextLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:11];
        _subtitleTextLabel.textColor = hexColor(333333);
    }
    return _subtitleTextLabel;
}

- (UIImageView *)rightArrowImageView {
    if (!_rightArrowImageView) {
        _rightArrowImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"jiantou"] changeWithNewTintColor:hexColor(999999)]];
        _rightArrowImageView.center = CGPointMake(ScreenWidth-20, (LSPersonalInfoTextCellHeight-10)/2+10);
    }
    return _rightArrowImageView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

@end
